package 力扣日常刷题.木22二月.第18天224;

/**
 * @author 帅小伙
 * @date 2022/2/24
 * @description
 */
public class Demo143丑数 {

    public int nthUglyNumber(int n) {
        int[] ans = new int[n];
        ans[0] = 1;

        int a=0,b=0,c=0;
        for (int i = 1; i < n; i++) {
             int na= ans[a] * 2,nb = ans[b] * 3 , nc  = ans[c] * 5;
             int min = Math.min(Math.min(na,nb),nc);
             ans[i] = min;
             if(min == na) a++;
             if(min == nb) b++;
             if(min == nc) c++;
        }
        return ans[n - 1];
    }

}
